import 'package:enjoy_plus_three2/utils/http.dart';
import 'package:enjoy_plus_three2/utils/toast.dart';
import 'package:flutter/material.dart';
import 'package:flutter_html/flutter_html.dart';

class NoticeDetail extends StatefulWidget {
  const NoticeDetail({super.key});

  @override
  State<NoticeDetail> createState() => _NoticeDetailState();
}

class _NoticeDetailState extends State<NoticeDetail> {

  Map notifyDetail = { };
  Map<String, dynamic> params = {};
@override
  void didChangeDependencies() {
    final data = ModalRoute.of(context)?.settings.arguments;
    // logger.i(data);
    //数据存在时进行map
    if (data != null) {
      //数据类型string，后为动态
      params = data as Map<String, dynamic>;
      //调用获取数据
      getNotifyDetail();
    }
    super.didChangeDependencies();
  }

   // 获取公告详情
  getNotifyDetail() async {
    final res = await http.get('/announcement/${params['id']}');
    if (res['code'] != 10000) return ToastUtils.showError('公告详情获取失败~');
    setState(() {
      //赋值
      notifyDetail = res['data'];
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('公告详情'),
      ),
      body: ListView(
        children: [
          Container(
            padding: const EdgeInsets.all(10),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                // 标题
                Text(
                  notifyDetail['title']?? '',
                  style: const TextStyle(
                    fontSize: 18,
                    fontWeight: FontWeight.bold,
                  )
                ),
                const SizedBox(height: 10),
                Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Text(
                      notifyDetail['creatorName']?? '',
                      style: const TextStyle(
                        color: Colors.grey
                      )
                    ),
                    Text(
                      notifyDetail['createdAt']?? '',
                      style: const TextStyle(
                        color: Colors.grey
                      )
                    )
                  ]
                ),
                const SizedBox(height: 10),
                // 内容
                Html(
                  data: notifyDetail['content']?? '',
                )
              ]
            )
          )
        ]
      )
    );
  }
}
// js/ts/arkts
//逻辑运算符 逻辑或｜｜一真则真
//a || b a为假时执行b
//假的定义为false
//‘’，0，false，unddiefined，null



//在flutter中
//？？条件访问运算符，成为null合并运算符
//a？？b
//只有a为null，才会执行b